package SpringFramework.Scope;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import SpringFramework.Scope.config.JavaConfig;
import SpringFramework.Scope.service.DemoPrototypeService;
import SpringFramework.Scope.service.DemoSingletonService;

public class Main {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = null;
		try {
			// 使用AnnotationConfigApplicationContext作为Spring容器，接受输入一个配置类作为参数。
			context = new AnnotationConfigApplicationContext(JavaConfig.class);
			
			DemoSingletonService s1 = context.getBean(DemoSingletonService.class);
			DemoSingletonService s2 = context.getBean(DemoSingletonService.class);
			System.out.println("s1与s2是否相等：" + s1.equals(s2));
			
			DemoPrototypeService p1 = context.getBean(DemoPrototypeService.class);
			DemoPrototypeService p2 = context.getBean(DemoPrototypeService.class);
			System.out.println("p1与p2是否相等：" + p1.equals(p2));
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if(context!=null) {
				context.close();
			}
		}
	}

}
